#include <iostream>
#include <filesystem>

#include "1-LexAnalysis/LexAnalysis.hpp"
#include "2-SyntaxAnalysis/SyntaxAnalysis.hpp"

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Command line: " << argv[0] << " <source file path>" << std::endl;
        std::exit(EXIT_FAILURE);
    }
    std::filesystem::path sourceFile(argv[1]);

    /* sourceFile path validity */
    if (!std::filesystem::exists(sourceFile))
    {
        std::cerr << "source file path invalid!!!" << std::endl;
        std::exit(EXIT_FAILURE);
    }
    else if (sourceFile.extension() != ".pas")
    {
        std::cerr << "source file type: *.pas" << std::endl;
        std::exit(EXIT_FAILURE);
    }

    /* 词法分析 */
    LexAnalysis lexAnalysis;
    lexAnalysis.lineScanner(sourceFile);

    std::cout << std::endl;

    /* 语法分析 */
    SyntaxAnalysis syntaxAnalysis;
    syntaxAnalysis.parser(sourceFile.replace_extension(".dyd"));

    return 0;
}
